<?php

class MainSearchForm extends BaseForm {
  const FORM_NAME           = 'frm';

  const FIELD_LOCATION      = 'location';
  const FIELD_RADIUS        = 'radius';
  const FIELD_MOVIE_TITLE   = 'movie_title';
  const FIELD_DATE          = 'date';
  const FIELD_TIME_FROM     = 'time_from';
  const FIELD_TIME_TO       = 'time_to';
  const FIELD_PRICE         = 'price';
  const FIELD_MERCHANT      = 'merchant';

  public function configure() {
    //$arrStatesList = STATETable::getInstance()->findAllArray(true);
    
    $arrMerchantsList = MERCHANTTable::getInstance()->findAllArray(true, true);

    $arrTimesList = array('' => '');
    for ($i=6; $i<=23; $i++) {
      $arrTimesList[date('H', mktime($i))] = date('h A', mktime($i));
    }

    $arrPricesList = array('' => '');
    $arrPricesList[5] = 'less than $5';
    $arrPricesList[10] = 'less than $10';
    $arrPricesList[0] = 'All';
    
    $arrDistanceList = array('' => '');
    $arrDistanceList[2] = 'Upto 2KM';
    $arrDistanceList[5] = 'Upto 5KM';
    $arrDistanceList[10] = 'Upto 10KM';
    $arrDistanceList['10+'] = 'Greater than 10KM';

    $widgets = array(
            self::FIELD_LOCATION      => new sfWidgetFormInputText(array(), array()),
            self::FIELD_RADIUS        => new sfWidgetFormSelect(array('choices' => $arrDistanceList)),
            self::FIELD_MOVIE_TITLE   => new sfWidgetFormInputText(array(), array()),
            self::FIELD_DATE          => new sfWidgetFormInputText(array(), array()),
            self::FIELD_TIME_FROM     => new sfWidgetFormSelect(array('choices' => $arrTimesList)),
            self::FIELD_TIME_TO       => new sfWidgetFormSelect(array('choices' => $arrTimesList)),
            self::FIELD_PRICE         => new sfWidgetFormSelect(array('choices' => $arrPricesList)),
            self::FIELD_MERCHANT      => new sfWidgetFormSelect(array('choices' => $arrMerchantsList))
    );

    $labels = array(
            self::FIELD_LOCATION      => 'Location',
            self::FIELD_RADIUS        => 'Distance from me',
            self::FIELD_MOVIE_TITLE   => 'Movie',
            self::FIELD_DATE          => 'Date',
            self::FIELD_TIME_FROM     => 'Time',
            self::FIELD_PRICE         => 'Price',
            self::FIELD_MERCHANT      => 'Cinema'
    );

    $this->setWidgets($widgets);
    $this->widgetSchema->setLabels($labels);
    
    $this->setDefault(self::FIELD_LOCATION, strtoupper(sfContext::getInstance()->getUser()->getAttribute(Constants::SESSION_USER_CITY)));

    $this->widgetSchema->setNameFormat(self::FORM_NAME . '[%s]');

    $this->validatorSchema->setOption('allow_extra_fields', true);
    $this->validatorSchema->setOption('filter_extra_fields', false);
  }
}
?>